<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%@ taglib uri="/WEB-INF/vectrics.tld"    prefix="vectrics" %>

<%@ taglib uri="/WEB-INF/hexacta.tld" prefix="hexacta"%>
<%@ page import="java.util.*"%>

<link rel="stylesheet" href="/hrs-intranet/styles/displaytag.css"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="/hrs-intranet/styles/jsgantt.css" />


<style>
* {
	padding: 0px;
	margin: 0px
}

.checkboxLabel {
	margin: 0px;
	padding: 0px
}
</style>



<script type="text/javascript">
	function revisarSeleccionDeDisponibilidad() {
		// Si se seleccionaron todos los checkbox, se tilda la opcion "Todos";
		// si no, se destilda esa opcion.
		if ((document.getElementById('noasignadocheckbox').checked)
				&& (document.getElementById('asignadoclientecheckbox').checked)
				&& (document.getElementById('addonavailablecheckbox').checked)
				&& (document.getElementById('addonnotavailablecheckbox').checked)
				&& (document.getElementById('internocheckbox').checked)
				&& (document.getElementById('timeoffcheckbox').checked))
			document.getElementById('todoscheckbox').checked = "checked";
		else
			document.getElementById('todoscheckbox').checked = "";
	}

	function tildarODestildarTodos() {
		// Si se deseleccionada la opcion "Todos", se tildan todos los otros checbox.
		if (document.getElementById('todoscheckbox').checked) {
			document.getElementById('noasignadocheckbox').checked = "checked";
			document.getElementById('asignadoclientecheckbox').checked = "checked";
			document.getElementById('addonavailablecheckbox').checked = "checked";
			document.getElementById('addonnotavailablecheckbox').checked = "checked";
			document.getElementById('internocheckbox').checked = "checked";
			document.getElementById('timeoffcheckbox').checked = "checked";
		} else {
			// Si se deseleccionada la opcion "Todos", se destildan todos los otros checbox.
			document.getElementById('noasignadocheckbox').checked = "";
			document.getElementById('asignadoclientecheckbox').checked = "";
			document.getElementById('addonavailablecheckbox').checked = "";
			document.getElementById('addonnotavailablecheckbox').checked = "";
			document.getElementById('internocheckbox').checked = "";
			document.getElementById('timeoffcheckbox').checked = "";
		}
	}

	function resetValues() {
		document.getElementById('resetAttributes').value = "true";
		document.getElementById('Search').click;
	}
</script>

<s:set name="searchButtonAction">
	<%=request.getParameter("requestURI")%>
</s:set>


<s:hidden id="resetAttributes" name="resetAttributes" />


<!-- Tabla de recursos disponibles con sus filtros -->

<table width="75%" class="TablaAvailableResources_fdo1">
	<tr>
		<td style="*padding-top: 5px"></td>
	</tr>
	<tr>
		<td width="60px" valign="middle" class="Dates">Start Date:</td>
		<td width="140px"><sx:datetimepicker id="startDate"
				name="selectedStartDate" displayFormat="dd/MM/yyyy"
				cssClass="WidthDate" /></td>

		<td width="50px" valign="middle" class="Dates">End Date:</td>
		<td width="150px"><sx:datetimepicker id="endDate"
				name="selectedEndDate" displayFormat="dd/MM/yyyy"
				cssClass="WidthDate" /></td>
		<td width="330px"></td>
	</tr>
	<tr>
		<td style="*padding-top: 5px"></td>
	</tr>
</table>

<table width="75%" class="TablaAvailableResources_fdo2">
	<tr>
		<td>
			<table width="130px" class="ShowTentatives">
				<tr>
					<td><s:checkbox label="Show tentatives"
							name="showTentativesAvailableResources" labelposition="left"
							labelSeparator="  " cssClass="ShowTentativesAdjust" /></td>
				</tr>
			</table></td>
	</tr>
	<tr>
		<td></td>
	</tr>

	<tr>
		<td>
			<table width="130" cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<table width="130px" class="NoAsignado">
							<tr>
								<td><s:checkbox id="noasignadocheckbox"
										labelposition="left" labelSeparator="  "
										onclick="revisarSeleccionDeDisponibilidad()"
										label="No asignado" name="showNoAsignado"
										cssClass="NoAsignadoAdjust" /></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td class="TablaAvailableResourcesSeparador"></td>
				</tr>
				<tr>
					<td>
						<table width="130px" class="AsignadoCliente">
							<tr>
								<td><s:checkbox id="asignadoclientecheckbox"
										labelposition="left" labelSeparator="  "
										onclick="revisarSeleccionDeDisponibilidad()"
										label="Asignado cliente" name="showAsignadoCliente"
										cssClass="AsignadoClienteAdjust" /></td>
							</tr>
						</table></td>
				</tr>
			</table></td>
		<td>
			<table width="130" cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<table width="130px" class="Add-onAvailable">
							<tr>
								<td><s:checkbox id="addonavailablecheckbox"
										onclick="revisarSeleccionDeDisponibilidad()"
										label="Add-on available" labelposition="left"
										labelSeparator="  " name="showAddOnAvailable"
										cssClass="Add-onAvailableAdjust" /></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td class="TablaAvailableResourcesSeparador"></td>
				</tr>
				<tr>
					<td>
						<table width="130px" class="Add-onNotAvailable">
							<tr>
								<td><s:checkbox id="addonnotavailablecheckbox"
										onclick="revisarSeleccionDeDisponibilidad()"
										label="Add-on not available" labelposition="left"
										labelSeparator="  " name="showAddOnNotAvailable"
										cssClass="Add-onNotAvailableAdjust" /></td>
							</tr>
						</table></td>
				</tr>
			</table></td>
		<td>
			<table width="130" cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<table width="130px" class="Interno">
							<tr>
								<td><s:checkbox id="internocheckbox"
										onclick="revisarSeleccionDeDisponibilidad()" label="Interno"
										labelposition="left" labelSeparator="  " name="showInterno"
										cssClass="InternoAdjust" /></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td class="TablaAvailableResourcesSeparador"></td>
				</tr>
				<tr>
					<td>
						<table width="130px" class="TimeOff">
							<tr>
								<td><s:checkbox id="timeoffcheckbox" labelposition="left"
										labelSeparator="  "
										onclick="revisarSeleccionDeDisponibilidad()" label="Time Off"
										name="showTimeOff" cssClass="TimeOffAdjust" /></td>
							</tr>
						</table></td>
				</tr>
			</table></td>
		<td>
			<table width="130" cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<table width="130px" class="Todos">
							<tr>
								<td><s:checkbox id="todoscheckbox" labelposition="left"
										labelSeparator="  " onclick="tildarODestildarTodos()"
										label="Todos" name="showTodos" cssClass="TodosAdjust" /></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td class="TablaAvailableResourcesSeparador"></td>
				</tr>
				<tr>
					<td>
						<table width="130px" class="Vacio">
							<tr>
								<td></td>
							</tr>
						</table></td>
				</tr>
			</table></td>
		<td>
			<table width="250" cellpadding="0" cellspacing="0" class="Roles">
				<tr>
					<s:select label="Roles" value="selectedRolesBefore" size="3"
						labelposition="top" name="selectedRoles" list="roles"
						listKey="code" listValue="description" multiple="true"
						title="Using Crtl, you can select multiple options. If no option is selected, all the roles will be shown"
						cssClass="RolesAdjust" />
				</tr>
			</table></td>
	</tr>
</table>

<table width="75%" class="TablaAvailableResources_fdo3">
	<s:if
		test="%{#searchButtonAction == 'EmployeeAssignmentAction_listAssignments'}">
		<tr>
			<td width="30%"><table><sx:autocompleter list="employeeList"
					listValue="person.name" searchType="startword" listKey="id"
					showDownArrow="false" keyName="selectedEmployeeId"
					name="selectedEmployeeName" label="Employee" cssStyle="width:250px" /></table>
			</td>
			<td><table><s:select list="locationList" listValue="name"
					key="selectedLocationId" name="selectedLocationId" listKey="id"
					label="Location" cssStyle="width:250px"  /></table>
			</td>
			<!-- <td width="50px" style="background-color: #fff"></td> -->
		</tr>
		<tr>
			<td colspan="2"><table><sx:autocompleter list="projectsList" listValue="name"
					searchType="startword" listKey="id" showDownArrow="false"
					keyName="selectedProjectIdFilter" name="selectedProjectNameFilter"
					label="Project" cssStyle="width:250px" /></table>
			</td>
		</tr>
	</s:if>
	<s:else>
		<tr>
			<td><sx:autocompleter list="projectsList" listValue="name"
					searchType="startword" listKey="id" showDownArrow="false"
					keyName="selectedProjectIdFilter" name="selectedProjectNameFilter"
					label="Project" cssStyle="width:272px" /></td>
			<td width="50px" style="background-color: #fff"></td>
		</tr>
		<tr>
			<sx:autocompleter list="employeeList" listValue="person.name"
				searchType="startword" listKey="id" showDownArrow="false"
				keyName="selectedEmployeeId" name="selectedEmployeeName"
				label="Employee" cssStyle="width:272px" />
		</tr>
	</s:else>
	<tr>
		<td colspan="2" align="left"><table>
		<s:checkbox id="elegibleprojectcheckbox" labelposition="right"
			labelSeparator="  " label="Only assignable as project member"
			name="onlyElegibleProjectMember" cssClass="ElegibleAdjust" /></table>
		</td>
	</tr>
	<tr>
		<td align="right"><table><s:submit key="Search" cssClass="btn" id="okbtn"
				action="%{#searchButtonAction}" /></table>
		</td>
		<td align="left"><table><s:submit key="Reset" cssClass="btn" id="rstbtn"
				onclick="resetValues()" /></table>
		</td>

	</tr>
</table>
<!-- Tabla de recursos disponibles -->
<s:set name="listArray">
	<%=request.getParameter("list")%>
</s:set>

<%
    String requestURI = request.getParameter("requestURI");
%>
<%
    String addEditURI = request.getParameter("addEditURI");
%>
<%
    String list = request.getParameter("list");
%>
<%
    String optionToShow = request.getParameter("optionToShowInGantt");
%>

<s:if test="%{#listArray.size()==0}">
	<table width="67%">
		<tr>
			<td><s:label label="No matches found." cssClass="formClass"></s:label>
			</td>
		</tr>
	</table>
</s:if>
<s:else>
	<jsp:include page="availableResources.jsp">
		<jsp:param name="requestURI" value="<%= requestURI %>" />
		<jsp:param name="addEditURI" value="<%= addEditURI %>" />
		<jsp:param name="list" value="<%= list %>" />
		<jsp:param name="optionToShowInGantt" value="<%= optionToShow %>" />
	</jsp:include>
</s:else>
